<?php

namespace App\Service\Adolescent;

use App\Constants\ErrorCode;
use App\Model\AdolescentPassword;
use App\Service\BaseService;
use Exception;

class ForgetAdolescentService extends BaseService
{
    /**
     * 忘记密码
     * @return array
     * @throws Exception
     */
    public function handle(): array
    {
        $userId = $this->getUserId();
        if (!$userId) {
            return $this->setError(1);
        }

        $adolescentPasswordModel = new AdolescentPassword();
        $info = $adolescentPasswordModel->getInfoByUserId($userId);
        if (!$info) {
            return $this->setError(0, '未开启青少年模式，请重启应用浏览');
        }

        $info->delete();
        return ['result' => 1];
    }
}